<template>
  <div class="station-info-dialog">
    <header>站点信息</header>
    <div class="bus-name">{{stationName}}</div>
    <div class="info-item" v-for="(item, index) in stationInfoList" :key="index">
      <div class="label">{{item.label}}</div>
      <div class="value">
        <template v-if="Object.prototype.toString.call(item.value) === '[object Array]'">
          <template v-if="item.label === '即将到达：'">
            <div class="value-item" v-for="(value, order) in item.value" :key="order">
              <div class="content">{{value.cph}}</div>
              <div class="icon" v-if="item.hasOwnProperty('icon')">
                <img :src="item.icon" alt="图标" />
              </div>
            </div>
          </template>
          <template v-else-if="item.label === '最近经过：'">
            <div class="value-item" v-for="(value, order) in item.value" :key="order">
              <div class="content">{{value.cph}}</div>
              <div class="icon" v-if="item.hasOwnProperty('icon')">
                <img :src="item.icon" alt="图标" />
              </div>
            </div>
          </template>
          <template v-else-if="item.label === '站点监控：'">
            <div class="value-item" v-for="(value, order) in item.value" :key="order">
              <div class="content">{{value.sbmc}}</div>
              <div class="icon" v-if="item.hasOwnProperty('icon')">
                <img :src="item.icon" alt="图标" />
              </div>
            </div>
          </template>
        </template>
        <div class="value-item" v-else>
          <div class="content">{{item.value}}</div>
          <div class="icon" v-if="item.hasOwnProperty('icon')">
            <img :src="item.icon" alt="图标" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { getStationDetail } from 'api/situationAwareness/busWay/screenCenter'
import Bus from 'utils/eventBus'

@Component({
  name: 'station-info-dialog'
})

export default class StationInfoDialog extends Vue {
  private stationInfoList: Array<any> = [
    { label: '途经车辆：', value: '' },
    { label: '今日客流：', value: '' },
    { label: '即将到达：', value: [], icon: require('assets/images/situational-awareness/dingwei.png') },
    { label: '最近经过：', value: [] },
    { label: '站点监控：', value: [], icon: require('assets/images/situational-awareness/jiankong.png') }
  ]

  private stationName = ''

  created () {
    Bus.$off('showBusWayStationDialog', this.getStationDetail)
    Bus.$on('showBusWayStationDialog', this.getStationDetail)
  }

  // 获取站点详情
  private async getStationDetail ({ id }: { id: string }) {
    const params = {
      stationId: id
    }
    try {
      const res: any = await getStationDetail(params)
      console.log('获取站点详情', res)
      const { stationName, routeName, passengerflow, arriveBusList, arrivedBusList, deviceId } = res.data
      this.stationName = stationName
      this.stationInfoList = [
        { label: '途经车辆：', value: routeName },
        { label: '今日客流：', value: passengerflow },
        { label: '即将到达：', value: arriveBusList, icon: require('assets/images/situational-awareness/dingwei.png') },
        { label: '最近经过：', value: arrivedBusList },
        { label: '站点监控：', value: deviceId, icon: require('assets/images/situational-awareness/jiankong.png') }
      ]
    } catch (err) {
      console.error(err)
    }
  }
}
</script>

<style lang="scss" scoped>
img {
  width: 100%;
  height: 100%;
  float: left;
}
.station-info-dialog {
  width: 294px;
  background: rgba(1, 19, 67, 1);
  border-radius: 8px;
  border: 2px solid #037ddc;
  box-shadow: 0px 0px 10px 2px #037ddc;
  box-sizing: border-box;
  padding: 4px 18px 18px;
  position: absolute;
  bottom: 0;
  left: -147px;
  header {
    height: 54px;
    line-height: 54px;
    font-size: 20px;
    font-family: 'PingFang Regular';
    font-weight: bold;
    color: #fff;
  }
  .bus-name {
    font-size: 14px;
    font-family: 'PingFang Regular';
    color: #fff;
    height: 26px;
    line-height: 26px;
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding-left: 18px;
    position: relative;
    &::before {
      content: '';
      position: absolute;
      width: 8px;
      height: 8px;
      background: #0c81fe;
      border-radius: 50%;
      left: 0px;
      top: 9px;
    }
  }
  .info-item {
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding-left: 18px;
    position: relative;
    &::before {
      content: '';
      position: absolute;
      width: 8px;
      height: 8px;
      background: #0c81fe;
      border-radius: 50%;
      left: 0px;
      top: 9px;
    }
    .label {
      font-size: 14px;
      font-family: 'PingFang Regular';
      color: #fff;
      height: 26px;
      line-height: 26px;
      width: 70px;
    }
    .value {
      width: calc(100% - 70px);
      &-item {
        display: flex;
        align-items: center;
        .content {
          font-size: 14px;
          font-family: 'PingFang Regular';
          color: #fff;
          min-height: 26px;
          line-height: 26px;
          word-break: break-all;
        }
        .icon {
          width: 16px;
          height: 16px;
          margin-left: 10px;
        }
      }
    }
  }
}
</style>
